<?php

namespace App\Transformers;

use App\Models\RedeemLog;
use League\Fractal\TransformerAbstract;

class RedeemLogTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['manager', 'user', 'prize', 'filiale'];

    public function transform(RedeemLog $redeemLog)
    {
        return [
            'id' => $redeemLog->id,
            'prize_id' => (int) $redeemLog->prize_id,
            'user_id' => (int) $redeemLog->user_id,
            'company_userid' => (int) $redeemLog->company_userid,
            'filiale_id' => (int) $redeemLog->filiale_id,
            'remark' => $redeemLog->remark,
            'created_at' => $redeemLog->created_at->toDateTimeString(),
            'updated_at' => $redeemLog->updated_at->toDateTimeString(),
        ];
    }

    public function includeUser(RedeemLog $redeemLog)
    {
        return $this->item($redeemLog->user, new UserTransformer());
    }

    public function includeManager(RedeemLog $redeemLog)
    {
        return $this->item($redeemLog->manager, new UserTransformer());
    }

    public function includePrize(RedeemLog $redeemLog)
    {
        return $this->item($redeemLog->prize, new PrizeTransformer());
    }

    public function includeFiliale(RedeemLog $redeemLog)
    {
        return $this->item($redeemLog->filiale, new FiliateTransformer());
    }
}